package com.cy.entity;

import java.util.List;
import java.util.Map;

import com.github.pagehelper.PageInfo;

public class JsonResult<T> {

	public static final int SUCCESS=0;
	
	private int state;
	private String message ="";
	private T data;
	private List<T> datas;
	//分页特化处理
	private PageInfo<T> pagedatas;
	//total and rows专门给bootstrap table做适配
	private long total;
	private List<T> rows;
	private Map<String, Object> map;
	public JsonResult(Map<String, Object> map) {//SUCCESS
		this.state =SUCCESS;
		this.map =map;
		
	}
	//处理字符串数据
	public JsonResult(String message) {//SUCCESS
		this.state =SUCCESS;
		this.message =message;
		
	}
	public JsonResult(int state, String message) {//ERROR
		this.state =state;
		this.message =message;
		
	}
	//处理对象数据
	public JsonResult(T data) {
		this.state = SUCCESS;
		this.data = data; 
	}
	
	public JsonResult(String message, T data) {
		this.state = SUCCESS;
		this.message =message;
		this.data = data; 
	}
	
	//处理集合数据
	public JsonResult(List<T> datas) {
		this.state = SUCCESS;
		this.datas = datas; 
	}
	
	public JsonResult(String message, List<T> datas) {
		this.state = SUCCESS;
		this.datas = datas; 
		this.message = message;
	}
	
	public JsonResult(int state, String message, T data) {
		this.state = state;
		this.message =message;
		this.data = data; 
	}
	//处理分页数据
	public JsonResult(PageInfo<T> pagedatas) {
		this.state = SUCCESS;
		this.pagedatas = pagedatas;
	}
	
	
	public int getState() {
		return state;
	}
	
	public void setState(int state) {
		this.state = state;
	}
	public String getMessage() {
		return message;
	}
	public void setMessage(String message) {
		this.message = message;
	}
	public T getData() {
		return data;
	}
	public void setData(T data) {
		this.data = data;
	}
	public List<T> getDatas() {
		return datas;
	}
	public void setDatas(List<T> datas) {
		this.datas = datas;
	}
	public PageInfo<T> getPagedatas() {
		return pagedatas;
	}
	public void setPagedatas(PageInfo<T> pagedatas) {
		this.pagedatas = pagedatas;
	}
	public long getTotal() {
		return pagedatas!=null?pagedatas.getTotal():0;
	}
	
	public List<T> getRows() {
		return pagedatas!=null?pagedatas.getList():null;
	}
	public static JsonResult okResult(Object url) {
		JsonResult result = new JsonResult<>((String)url);
		return result;
	}
	
	
}
